﻿using Microsoft.AspNetCore.Mvc;
using OnlineCourse.Services;
using System.Linq;
using OnlineCourse.Model;
using System.Threading.Tasks;
using OnlineCourse.Model.Entity;
using System;
using System.Collections.Generic;

namespace OnlineCourse.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class PaymentTypeController : ControllerBase
    {
        private readonly PaymentTypeService _paymentTypeService;
        public PaymentTypeController (ApplicationDbContext db)
        {
            this._paymentTypeService = new PaymentTypeService(db) ;
        }
        [HttpPost("GetList")]
        public List<PaymentType> GetList()
        {
            return  _paymentTypeService.GetList();
        }
        [HttpPost("Add")]
        public async Task<IActionResult> AddPaymentType(string title,decimal price,decimal AccountMoney)
        {
            PaymentType pt = new PaymentType();
            pt.Title = title;
            pt.Price = price;
            pt.AccountMoney = AccountMoney;
            if(_paymentTypeService.AddPaymentType(pt))
            {
                return Ok(true);
            }
            else
            {
                return Ok(false);
            }

        }
        [HttpPost("Update")]
        public async Task<IActionResult> UpdatePaymentType(Guid id,string title,decimal price,decimal AccountMoney)
        {
            PaymentType pt = new PaymentType();
            pt.Title = title;
            pt.Price = price;
            pt.AccountMoney = AccountMoney;
            if(_paymentTypeService.UpdatePaymentType(id,pt))
            {
                return Ok(true);
            }
            else
            {
                return Ok(false);
            }
        }
        [HttpPost("Delete")]
        public async Task<IActionResult> DeletePaymentType(Guid id)
        {
            bool mark = false;
            await Task.Run(()=> {mark = _paymentTypeService.DeletePaymentType(id); });
            if(mark)
            {
                return Ok(true);
            }
            else
            {
                return Ok(false);
            }
        }
    }
}